package com.hang.controller;

import com.hang.common.Result;
import com.hang.exception.MyException;
import com.hang.model.dto.request.UserInfoRegisterDTO;
import com.hang.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@Api(tags = "注册管理模块")
@RequestMapping("register")
@Slf4j
public class RegisterController {
    @Resource
    private IUserService userService;

    @PostMapping("user")
    @ApiOperation(value = "注册用户")
    public Result registerUser(@RequestBody @Valid UserInfoRegisterDTO userInfoRegisterDTO){
        try {
            Boolean registerSuccess =  userService.registerUser(userInfoRegisterDTO);
            return Result.ok(registerSuccess).message("注册成功");
        }catch (MyException me){
            return Result.fail().message(me.getMessage());
        }
    }
}
